Ext.ns('Wlanauth.system');

Wlanauth.system.ConfigPanel = Ext.extend(Ext.Panel,{
	title:'系统配置',
	
	constructor:function(config){
		Ext.applyIf(this,config);
	 	
		this.radiusSettingForm = new Wlanauth.BaseFormPanel({
			padding:5,
			frame:false,
			actionClass:'radRatio',
			firstFlag:true,
			tbar:[{text:'保存',handler:function(){
				var formPanel = this.ownerCt.ownerCt;
				if(formPanel.firstFlag){
					formPanel.getForm().findField('entity.id').setValue('');
		 			formPanel.firstFlag = false;
		 		} 
				formPanel.doSubmit();
			}},'->',''],
			
			items:[{
				fieldLabel:'计费比率',
				xtype: 'compositefield',
                combineErrors: false,
                items: [{
                	xtype: 'displayfield',width:40,value:'1',cls:'x-field-display'
                },{
                	xtype: 'displayfield',value: 'KB / ',width:40
                },{
                	name : 'entity.value',xtype: 'numberfield',
                	key:'RADIUS_RATIO',width: 100,allowBlank: false
                },{
                	xtype: 'displayfield',value: '元'
                }]
			},{
				fieldLabel:'备注',
				xtype:'textarea',
				name:'entity.description',
				anchor:'80%'
			},{
				xtype:'hidden',
				name:'entity.id'
			},{
				xtype:'hidden',
				name:'entity.unit',
				value:'KB/元'
			}]
		});
		
		this.ratiohisGrid = new Wlanauth.BaseGridPanel({
			autoHeight:true,
			pageSize:10,
			store:new Ext.data.JsonStore({
				url:'radRatio!list.action',
				totalProperty:'data',
				root:'rows',
				fields:['id','unit','value','description',
				        {name:'effectTime',type:'date',dateFormat:'Y-m-d H:i:s'}]
				
			}),
			cm:new Ext.grid.ColumnModel({
				columns:[
					{header:'ID',dataIndex:'id',width:120},
					{header:'值',dataIndex:'value',width:120,sortable:true},
				    {header:'单位',dataIndex:'unit',width:120},
				    {header:'生效日期',dataIndex:'effectTime',width:120,renderer:Ext.util.Format.dateRenderer("Y-m-d H:i:s"),sortable:true},
				    {header:'备注',dataIndex:'description',id:'desc'}
				   
			    ]}),
			    stripRows:true,
			    autoExpandColumn:'desc'
		});
		
		Wlanauth.system.ConfigPanel.superclass.constructor.call(this,{
			labelWidth:80,
			padding:5,
			autoScroll:true,
			items:[{
				title:'计费设置',
				xtype:'fieldset',
				items:[this.radiusSettingForm]
			},{
				title:'历史计费比率',
				xtype:'fieldset',
				items:this.ratiohisGrid
			}]
			
		});
		this.initData();
		
		this.radiusSettingForm.on('actionSuccess',function(form,action){
			this.ratiohisGrid.getStore().reload();
	 		Ext.Msg.alert('提示','操作成功,数据已保存!');
	 		form.findField('entity.id',true).setValue(action.result.data.id);
	 	},this);
		
		this.ratiohisGrid.fireEvent('autoload');
	},
	initData:function(){
		var form = this.radiusSettingForm.getForm();
		form.entityName='entity';
      	form.load({
      		//waitMsg:'正在加载数据...',
      		url:'radRatio!edit.action'
      	});
	}
});

Ext.reg('wlanauth.system.configpanel',Wlanauth.system.ConfigPanel);